package com.lmxdawn.api.dnf.util;

import cn.hutool.core.map.MapUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
@Slf4j
public class AuthUtil {

    public static void main(String[] args) {
        System.out.println(authCheck("4b42fc426568415595ed65a8b7828013", "黄毓斌", "350681199502131011"));

    }
    private static final String URL = "https://idenauthen.market.alicloudapi.com/idenAuthentication";

    public static boolean authCheck(String appCode ,String name ,String idNo){
//        String appCode = "4ccb83d3cacd4dbf8b7df835163a7a2a";cloudauth_infoverify_dp_cn
//        String appSecret = "OztCUqTGB8Z4euF6M6IE6vAJSD1kmjRo";
      try {
          HashMap<String, Object> map = MapUtil.of("name", name );
          map.put("idNo", idNo);
          HttpRequest post = HttpUtil.createPost(URL);
          post.header("Authorization", "APPCODE " + appCode);
          post.header("Content-Type", "application/x-www-form-urlencoded");
          HttpResponse execute = post.form(map).execute();
          log.info(execute.body());
          return execute.getStatus() == 200 && JSON.parseObject(execute.body()).getString("respCode").equals("0000");
      }catch (Exception e){
          e.printStackTrace();
          return false;
      }
    }
}


